/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utilidades;

/**
 *
 * @author Eugenio
 */


import java.awt.Color;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JRadioButton;
import javax.swing.text.JTextComponent;

public class Utilidad {
	public static boolean isPalabraVacia(String... palabras) {
		for (String palabra : palabras) {
			if (palabra == null || palabra.trim().length() == 0) {
				throw new CampoVacioException();
			}
		}
		return false;
	}

	public static void limpiarCampos(JComponent... campos) {
		for (int i = 0; i < campos.length; i++) {
			if (campos[i] instanceof JComboBox) {
				((JComboBox) (campos[i])).setSelectedIndex(0);
			} else if (campos[i] instanceof JTextComponent) {
				((JTextComponent) (campos[i])).setText("");
			} else if (campos[i] instanceof JRadioButton) {
				((JRadioButton) (campos[i])).setSelected(false);
			} /*
			 * else if (campos[i] instanceof JSpinner) { ((JSpinner)
			 * (campos[i])).removeAll(); }
			 */
		}
	}

	public static void asignarCamposNecesarios(final JTextComponent... componentes) {

		for (final JTextComponent txt : componentes) {
			txt.addFocusListener(new java.awt.event.FocusAdapter() {
				@Override
				public void focusLost(java.awt.event.FocusEvent e) {
					txt.setBackground(Color.white);
					txt.setForeground(Color.BLACK);
				}

				@Override
				public void focusGained(java.awt.event.FocusEvent e) {
					for (int i = 0; i < componentes.length; i++) {
						txt.setForeground(Color.WHITE);
						txt.setBackground(new Color(72, 129, 191));
					}

				}
			});
		}
	}

}

